#include "test_max.h"
#include <cassert>

#include "lib.h"

static void __assert_max(const int expect, const int left, const int right){
		int result = max(left, right);
		assert(expect == result);
}
void test_max(){
	__assert_max(10, 10, 1);
	__assert_max(10, 1, 10);
	__assert_max(3, 2, 3);
	__assert_max(4, 4, 4);
	__assert_max(0, 0, 0);
}





static void __assert_max_array(bool ok, int expect, int * array, size_t len)
{
	int result ;
	assert(max(array, len, &result) == ok && result == expect);
}
static void __assert_max_array_false(int * array, size_t len){
	int result ;
	assert(max(array, len, &result) == false);
}


void test_max_array(){
	{
		int array [] = {1, 10, -10, 23};
		__assert_max_array(true, 23, array, sizeof(array)/sizeof(int));
	}		

	{
		int array [] = {1, 10, -10, 12};
		__assert_max_array(true, 12, array, sizeof(array)/sizeof(int));
	}

	{
		int array [] = {3};
		__assert_max_array(true, 3, array, sizeof(array)/sizeof(int));
	}

	{
		int array [] = {};
		__assert_max_array_false(array, sizeof(array)/sizeof(int));
	}
	{
		__assert_max_array_false(nullptr, 10);
	}
	{
		int array [] = {};
		bool ok = max(array, sizeof(array)/sizeof(int), nullptr);
		assert(ok == false);
	}
	{
		int array [] = {3};
		bool ok = max(array, sizeof(array)/sizeof(int), nullptr);
		assert(ok == false);
	}
}
